﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PhotoGallery.Core.Business;
using System.IO;
using PhotoGallery.Infrastructure;

namespace PhotoGallery.Core.Business
{
    /// <summary>
    /// 文件夹搜索条件
    /// </summary>
    public class FolderSearch
    {
        #region  Field

        public int Id { get; set; }

        public string FolderName { get; set; }

        public string KeyWord { get; set; }

        public string Photographer { get; set; }

        public string Leader { get; set; }

        public string OtherLeader { get; set; }

        public string Guest { get; set; }

        public string Location { get; set; }

        public int EventInfo { get; set; }

        public string EventInfoDesc { get; set; }

        public int? Status { get; set; }

        #endregion

        #region Constructor


        public FolderSearch()
        {
            
        }

        #endregion

    }

    /// <summary>
    /// 文件夹
    /// </summary>
    public class Folder
    {
        #region Field & Property

        /// <summary>
        /// 文件节点
        /// </summary>
        public PicNode PicNode { get; protected set; }

        /// <summary>
        /// 文件夹描述信息
        /// </summary>
        public FolderDesc FolderDesc { get; protected set; }

        /// <summary>
        /// 文件内子文件信息
        /// </summary>
        public IList<FileInfo> FileInfos { get; protected set; }

        /// <summary>
        /// 文件夹中子文件夹信息
        /// </summary>
        public IList<DirectoryInfo> DictionaryInfos { get; protected set; }

        #endregion


        #region Constructor

        protected Folder()
        {

        }

        public Folder(PicNode node, FolderDesc desc)
        {
            if (node == null)
                throw new ArgumentException("文件夹节点不能为空！");
            this.PicNode = node;
            this.FolderDesc = desc;


            // 核心代码如下：根据文件的路径查找文件信息

            DirectoryInfo dir = new DirectoryInfo(FileConfiguration.FullPath + this.PicNode.Path.Replace("/", @"\\"));

            if (!dir.Exists)
                dir.Create();

            this.FileInfos = dir.GetFiles("*.*");

            this.DictionaryInfos = dir.GetDirectories("*.*");

        }

        #endregion


    }

    /// <summary>
    /// 文件搜索 视图模型
    /// </summary>
    public class FolderSearchModel
    {

        #region Field & Property

        /// <summary>
        /// 搜索条件
        /// </summary>
        public FolderSearch Search { get; set; }

        /// <summary>
        /// 文件夹
        /// </summary>
        public IList<Folder> Folders { get; set; }

        #endregion

        #region Constructor

        public FolderSearchModel()
        {

        }

        public FolderSearchModel(FolderSearch Search, IList<Folder> Folders)
        {
            this.Search = Search;
            this.Folders = Folders;
        }

        #endregion
    }



}
